package com.rn.gypsophila.redis.queue.pubsub;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;

/**
 * Description: Redis消息发布者实现
 *
 * @author 然诺
 * @date 2020/05/09
 */
public class RedisMessagePublisher implements MessagePublisher {

	private RedisTemplate redisTemplate;
	private ChannelTopic topic;

	public RedisMessagePublisher() {
	}

	public RedisMessagePublisher(RedisTemplate redisTemplate, ChannelTopic topic) {
		this.redisTemplate = redisTemplate;
		this.topic = topic;
	}

	@Override
	public void publish(String message) {
		redisTemplate.convertAndSend(topic.getTopic(), message);
	}

}
